export const custom = {
	loading: true,
	auth: true,
	toast: true,
	catch: true,
	tokenPrefix: "Bearer",
	tokenNeedPrefix: false
}

export const handleParams = (config = {}) => {
	return uni.$u.deepMerge({
		custom: custom
	}, config)
}

export const formatGetParams = ({
	config,
	params
}) => {
	return {
		...handleParams(config),
		data: {
			...params
		}
	}
}

export const formatToken = (token, custom = custom) => {
	if (!token) return token;
	const prefix = custom.tokenPrefix ?? "Bearer";
	let result = token;
	if (custom.auth) {
		const has = token.includes(prefix)
		if (custom.tokenNeedPrefix && !has) result = `${prefix} ${token}`
	}
	return result
}
